package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.bean.Gam1;
import com.bw.bean.Gam2;
import com.bw.bean.Gam3;
import com.bw.service.GamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GamController {

    @Autowired
    GamService service;

    //条形统计图
    @RequestMapping("list")
    public JSONObject list(){
        List<Gam1> list = service.list();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject jsonObject1 = new JSONObject();

        JSONArray objects = new JSONArray();
        for (Gam1 gam1 : list) {
            String name1 = gam1.getName1();
            objects.add(name1);
        }
        jsonObject1.put("categories",objects);

        JSONArray objects1 = new JSONArray();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","销售金额");

        JSONArray objects2 = new JSONArray();
        for (Gam1 gam1 : list) {
            Double mout = gam1.getMout();
            objects2.add(mout);
        }
        jsonObject2.put("data",objects2);
        objects1.add(jsonObject2);
        jsonObject1.put("series",objects1);

        jsonObject.put("data",jsonObject1);
        return jsonObject;
    }

    //饼图
    @RequestMapping("list1")
    public JSONObject list1(){
        List<Gam2> gam2s = service.list2();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject jsonObject1 = new JSONObject();
        JSONArray objects = new JSONArray();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","各类销售占比");
        JSONArray objects1 = new JSONArray();
        for (Gam2 gam2 : gam2s) {
            Double avg = gam2.getAvg();
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("name","a"+1);
            jsonObject3.put("value",avg);
            objects1.add(jsonObject3);

        }
        jsonObject2.put("data",objects1);
        objects.add(jsonObject2);
        jsonObject1.put("series",objects);
        jsonObject.put("data",jsonObject1);
        return jsonObject;
    }


    //数字翻牌器
    @RequestMapping("list2")
    public JSONObject list2(){
        Gam3 gam3 = service.list3();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",gam3.getSum());
        return jsonObject;
    }
}
